//
//  ConfigHandler.m
//  Staff
//
//  Created by caiyao on 12/25/14.
//
//

#import "ConfigHandler.h"
#import "Constants.h"
#import "Config.h"
#import "ShareData.h"

@implementation ConfigHandler


- (void)downloadCheckSum {
    ChaosRequest *request = [[ChaosRequest alloc] init];
    
    request.connectionURLString = CONFIG_DOWNLOAD_LOC;
    request.delegate = self;
    request.httpMethod = @"POST";
    request.requestIdentifier = @"downloadChecksum";
    [[ChaosAgent sharedAgent] inqueue:request];
    [request release];
}

#pragma mark-
#pragma ChaosConnectionDelegate
- (void)response:(ChaosResponse *)resp {
    
////    Config *config = [Config parserConfigObjectWithJson:resp.jsonDictionary];
////    //                NSData *udObject = [NSKeyedArchiver archivedDataWithRootObject:config];
////    expectedLength = [(WebResource*)[config.webResources objectAtIndex:0] size];
////    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
////    [ud setObject:resp.jsonDictionary forKey:@"config"];
////    [ud synchronize];
//    
//    [[ShareData shareInstance] setLastConfigUpdateDate];
//    
//    if (![self isVersionUpgrade]) {
//        if (![self compareCheckSum:[[config.webResources objectAtIndex:0] hashCode]]) {
//            [self downloadResource];
//        } else {
//            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//            NSString *documentsDirectory = [paths objectAtIndex:0];
//            if (![[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@",documentsDirectory,[[config.webResources objectAtIndex:0] fileName]]]) {
//                [[ChaosFileFetcher sharedFetcher] unZipFile:file];
//            }
//            [self fetchDone];
//        }
//    } else {
//        [self startUpgradeApp];
//    }
//
    
    
}

- (void)receiveDataLength:(NSInteger)receivedDataLength identifer:(NSString *)identifer{
   
}


@end
